package com.sgb.kjwl.viewmodel.manage;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.manage.CompanyTradesListEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.view.ui.fragment.manage.BusinessDynamicsForWebsite;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BusinessDynamicsForWebsiteModel extends BaseViewModel {

    private BusinessDynamicsForWebsite fragment;

    private int page = 1;
    private int limit = 10;

    public BusinessDynamicsForWebsiteModel(BusinessDynamicsForWebsite fragment) {
        this.fragment = fragment;
    }

    public void getBusinessDynamicsList(String siteNo, int siteType, boolean isLoadMore) {
        Map<String, Object> map = new HashMap();
        page = isLoadMore ? page + 1 : 1;
        map.put("page", page);
        map.put("limit", limit);
        map.put("companyNo", siteNo);
        //map.put("siteNo", siteNo);
        //map.put("siteType", siteType + "");
        DialogHelper.showProgressDialog(fragment.getContext(), null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getCompanyTrends(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<CompanyTradesListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<CompanyTradesListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData().isLastPage()) {
                        fragment.showList(data.getData().getList(), isLoadMore, true);
                    } else {
                        fragment.showList(data.getData().getList(), isLoadMore, false);
                    }
                }
            }
        });
    }
}
